package 求区间和;

import java.util.Scanner;

/**
 * 给定n个正整数组成的数列a1,a2,...,an，和m个区间[li,ri],分别求m个区间的区间和。
 * 对于所有测试数据，n,m<=10^5,ai<=10^4。
 */
public class Demo01 {
    

    
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        //输入格式
        //第一行1,为一个正整数n
        int n = scanner.nextInt();
        //第二行n个正整数a1,a2,...,an
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        //第三行，为一个正整数m.
        int m = scanner.nextInt();
        //第四行到第m+3行，每一行为两个正整数li,ri
        int[][] intervals = new int[m][2];
        for (int i = 0; i < m; i++) {
            intervals[i][0] = scanner.nextInt();
            intervals[i][1] = scanner.nextInt();
        }
        //计算每个区间分别的区间和
        int[] sums = new int[m];
        for (int i = 0; i < m; i++) {
            int left = intervals[i][0]-1;
            int right = intervals[i][1]-1;
            int sum = 0;
            for (int j = left; j <= right; j++) {
                sum += a[j];
            }
            sums[i] = sum;
        }
        //输出结果
        for (int i = 0; i < m; i++) {
            System.out.println(sums[i]);
        }   
    }
}
